package com.kaishengit.pms.web;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.pms.entity.Employee;
import com.kaishengit.pms.service.EmployeeService;
import com.kaishengit.pms.service.ProjectService;

public class AddProjectServlet extends HttpServlet {

	private static final long serialVersionUID = 1L;

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		EmployeeService service = new EmployeeService();
		List<Employee> employeeList = service.findAll();
		
		request.setAttribute("employeeList", employeeList);
		request.getRequestDispatcher("/WEB-INF/views/new_project.jsp").forward(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		
		String name = request.getParameter("name");
		String desc = request.getParameter("desc");
		String manager = request.getParameter("manager");
		String worker = request.getParameter("workers");
		
		ProjectService service = new ProjectService();
		service.save(name,desc,manager,worker);
		
		response.sendRedirect("main.jspx");
	}

}
